package com.ellecity06.cwhiskymall.ui.live.chat

import android.app.Dialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.ellecity06.common.base.BaseBottomDialogFragment
import com.ellecity06.common.databinding.LayoutEmptyViewBinding
import com.ellecity06.common.helper.ClickHelper
import com.ellecity06.cwhiskymall.adapter.LiveGoodAdapter
import com.ellecity06.cwhiskymall.bean.response.LiveRoomGoodResponse
import com.ellecity06.cwhiskymall.databinding.DialogLiveRoomGoodBinding
import com.ellecity06.cwhiskymall.ui.webview.WebHelper

/**
 * @author ellecity06
 * @time 2025/1/11 17:32
 * @des
 */
class LiveGoodDialog : BaseBottomDialogFragment<DialogLiveRoomGoodBinding>() {
    private val adapter:LiveGoodAdapter by lazy { LiveGoodAdapter() }
    override val dimAmount: Float
        get() = 0.0f
    companion object{
        fun newInstance(): LiveGoodDialog {
            val liveGoodDialog = LiveGoodDialog()

           return liveGoodDialog
        }
    }

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = super.onCreateDialog(savedInstanceState)

        // 设置背景透明度
        if (dialog.window != null) {
            dialog.window!!.setDimAmount(dimAmount)
            dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        }
        return dialog
    }
    override fun inflateBinding(inflater: LayoutInflater, container: ViewGroup?): DialogLiveRoomGoodBinding {
        return DialogLiveRoomGoodBinding.inflate(inflater, container, false)
    }
    fun setGoodList(list: List<LiveRoomGoodResponse>?) {
        adapter.submitList(list)
    }
    private val emptyViewBinding by lazy { LayoutEmptyViewBinding.inflate(LayoutInflater.from(requireActivity()), binding.rvGood, false) }
    override fun initialize() {
        binding.rvGood.layoutManager = LinearLayoutManager(requireActivity())
        binding.rvGood.adapter = adapter
        adapter.emptyView = emptyViewBinding.root
        adapter.setOnItemClickListener { _, _, position ->
            ClickHelper.debounceClick {
                val item = adapter.getItem(position)
                WebHelper.goodDetails(requireActivity(),item?.goodId,1)
            }
        }
    }
}